<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------

namespace api\wxapp\controller;

use api\wxapp\controller\ApiBaseController;
use think\Db;
use api\wxapp\model\Activity;
class ActivityController extends ApiBaseController
{
    public function index()
    {   
        $info = Activity::where('status',2)->order('id desc')->all();
        $this->success('请求成功',$info);
    }
    public function sign()
    {
        $params = $this->getParam();
        $this->checkuid($params);
        if(!isset($params['activity_id'])){
            $this->error('参数缺失!!!!');
        }
        //查询  当前用户  是否已报名此活动
        $find = db::name('app_activity_list')->where(['uid'=>$params['uid'],'activity_id'=>$params['activity_id']])->find();
        if($find){
            $this->error('从活动已报名,不能重复报名!!!!');
        }
        $params['addtime'] = date('Y-m-d H:i:s',time());
        $res = db::name('app_activity_list')->insert($params);
        if($res){
            $this->success('报名成功',true);
        }else{
            $this->error('报名失败',false);
        }
        
    }
}
